<html>
<head><meta charset="utf-8"><title>const_evaluatable: subexpressions · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html">const_evaluatable: subexpressions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224169941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224169941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224169941">(Jan 27 2021 at 11:49)</a>:</h4>
<p>looking at the following test from <a href="https://github.com/rust-lang/rust/issues/81426">#81426</a></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(const_generics, const_evaluatable_checked)]</span><span class="w"></span>
<span class="cp">#![allow(incomplete_features)]</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">zero_init</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Substs1</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>: <span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Substs1</span><span class="p">([</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">])</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Substs1</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">([</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">])</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="p">[();</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>: <span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">substs2</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Substs1</span><span class="o">&lt;</span><span class="p">{</span><span class="w"> </span><span class="n">M</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">}</span><span class="o">&gt;</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="p">[();</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">M</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>: <span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">zero_init</span>::<span class="o">&lt;</span><span class="p">{</span><span class="w"> </span><span class="n">M</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">}</span><span class="o">&gt;</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">substs3</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">L</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Substs1</span><span class="o">&lt;</span><span class="p">{</span><span class="w"> </span><span class="p">(</span><span class="n">L</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">}</span><span class="o">&gt;</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="p">[();</span><span class="w"> </span><span class="p">(</span><span class="n">L</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)]</span>: <span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">[();</span><span class="w"> </span><span class="p">(</span><span class="n">L</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>: <span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">substs2</span>::<span class="o">&lt;</span><span class="p">{</span><span class="w"> </span><span class="n">L</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">}</span><span class="o">&gt;</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="fm">assert_eq!</span><span class="p">(</span><span class="n">substs3</span>::<span class="o">&lt;</span><span class="mi">2</span><span class="o">&gt;</span><span class="p">().</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="mi">3</span><span class="p">]);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="224170047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224170047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224170047">(Jan 27 2021 at 11:50)</a>:</h4>
<p>it's quite annoying that we have to explicitly mention these two const evaluatable predicates</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="p">[();</span><span class="w"> </span><span class="p">(</span><span class="n">L</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)]</span>: <span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">[();</span><span class="w"> </span><span class="p">(</span><span class="n">L</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>: <span class="p">,</span><span class="w"></span>
</code></pre></div>



<a name="224170127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224170127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224170127">(Jan 27 2021 at 11:51)</a>:</h4>
<p>considering that if <code>(L - 1) * 2 + 1</code> does not fail to evaluate, <code>(L - 1)</code> most certainly also evaluates successfully</p>



<a name="224170240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224170240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224170240">(Jan 27 2021 at 11:53)</a>:</h4>
<p>we could very easily try to match const eval predicates with subtrees of the const eval predicates in the caller bounds</p>



<a name="224170347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224170347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224170347">(Jan 27 2021 at 11:54)</a>:</h4>
<p>not sure if we already want to implement this now or wait until we get more experience with other potentially annoying cases</p>



<a name="224170393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224170393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224170393">(Jan 27 2021 at 11:55)</a>:</h4>
<p>it could always get its own feature gate</p>



<a name="224170408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224170408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224170408">(Jan 27 2021 at 11:55)</a>:</h4>
<p>then it can be talked about separately</p>



<a name="224170421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224170421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224170421">(Jan 27 2021 at 11:55)</a>:</h4>
<p><code>feature(const_evaluatable_checked_ergonomics)</code>? <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="224170585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224170585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224170585">(Jan 27 2021 at 11:57)</a>:</h4>
<p>yes, more underscores must mean the feature is better</p>



<a name="224170998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224170998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224170998">(Jan 27 2021 at 12:01)</a>:</h4>
<p><code>feature(cece)</code> seems good, i've been told that using acronyms is always a good thing</p>



<a name="224411936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224411936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224411936">(Jan 28 2021 at 23:59)</a>:</h4>
<p><del>This is probably important enough that it can just use the empty string as a feature gate. We've been saving that one for a special occasion.</del> Edit: my mistake, we permit empty feature lists.</p>



<a name="224417576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224417576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224417576">(Jan 29 2021 at 00:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions/near/224411936">said</a>:</p>
<blockquote>
<p><del>This is probably important enough that it can just use the empty string as a feature gate. We've been saving that one for a special occasion.</del> Edit: my mistake, we permit empty feature lists.</p>
</blockquote>
<p><code>feature(____________)</code> looks like a good enough substitute -- it has the most underscores!</p>



<a name="224614149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224614149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224614149">(Jan 31 2021 at 00:45)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions/near/224170393">said</a>:</p>
<blockquote>
<p>it could always get its own feature gate</p>
</blockquote>
<p>i think that i would pretty always want to keep that feature active so i am not sure if splitting it off is actually worth it</p>



<a name="224614158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224614158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224614158">(Jan 31 2021 at 00:45)</a>:</h4>
<p>going to leave the decision to <span class="user-mention" data-user-id="124288">@oli</span> ^^, i think i slightly prefer not adding an additional feature gate for this</p>



<a name="224704036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20subexpressions/near/224704036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20subexpressions.html#224704036">(Feb 01 2021 at 09:48)</a>:</h4>
<p>that was mainly meant to make the decision to add it easier if there were some concerns about always keeping it on. So fine by me to just activate it unconditionally</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>